﻿namespace Ops.Host.Core.Services.Impl;

internal sealed class PtProductionService : IPtProductionService
{
    private readonly SqlSugarRepository<PtMarkingData> _markingRepo;

    public PtProductionService(SqlSugarRepository<PtMarkingData> markingRepo)
	{
        _markingRepo = markingRepo;
    }

    public async Task<PagedList<PtMarkingData>> GetPagedListAsync(PtMarkingDataFilter filter, int pageIndex, int pageSize)
    {
        return await _markingRepo.AsQueryable()
                .WhereIF(!string.IsNullOrWhiteSpace(filter.SN), s => s.SN!.Contains(filter.SN!))
                .WhereIF(filter.MarkingTimeStart != null, s => s.MarkingTime >= filter.MarkingTimeStart.ToDayMin())
                .WhereIF(filter.MarkingTimeEnd != null, s => s.MarkingTime <= filter.MarkingTimeEnd.ToDayMax())
                .ToPagedListAsync(pageIndex, pageSize);
    }
}
